package com.myjavalab.collection;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;

import com.myjavalab.util.PrintUtil;

public class IteratorTest {
	
	/*
	 *  test fail-fast of iterator
	 */
	public static void main(String[] args) {
		ArrayList<String> list = new ArrayList<String>();
		list.add("xx");
		list.add("xx");
		list.add("xx");
		list.add("xx");
		ListIterator<String> it = list.listIterator();
		while(it.hasNext()){
			PrintUtil.prt(it.next());
//			it.remove();
			it.add("yyyy");
			//list.add("xx");   // throw java.util.ConcurrentModificationException
		}
		PrintUtil.prt(list.size());
		for(String s : list) {
			PrintUtil.prt(s);
		}
	}
}
